package com.qqtech.qquan.circle.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.qqtech.core.frame.dao.BaseDaoImpl;
import com.qqtech.qquan.circle.model.CircleMember;
import com.qqtech.qquan.circle.model.CircleMemberQuery;
import com.qqtech.qquan.circle.model.CircleMemberVo;

@Repository
public class CircleMemberDaoImpl extends BaseDaoImpl<CircleMember> implements CircleMemberDao {
	public static final Logger log = LoggerFactory.getLogger(CircleMemberDaoImpl.class);

	@Override
	public List<Integer> queryMyCircleIds(CircleMemberQuery query) {
		return sqlSessionTemplate.selectList(getSqlName("queryMyCircleIds"), query);
	}
	@Override
	public List<Integer> queryMyOrderlyCircleIds(Integer userId) {
		return sqlSessionTemplate.selectList(getSqlName("queryMyOrderlyCircleIds"), userId);
	}

	@Override
	public List<Integer> queryMyJoinCircleIds(Integer userId) {
		return sqlSessionTemplate.selectList(getSqlName("queryMyJoinCircleIds"), userId);
	}
	
	@Override
	public List<Integer> queryMyOpenCircleIds(Integer userId) {
		return sqlSessionTemplate.selectList(getSqlName("queryMyOpenCircleIds"), userId);
	}

	@Override
	public List<Integer> queryMyManageCircleIds(Integer userId) {
		return sqlSessionTemplate.selectList(getSqlName("queryMyManageCircleIds"), userId);
	}

	@Override
	public List<Integer> queryCircleIds(CircleMemberQuery circleMemberQuery) {
		return sqlSessionTemplate.selectList(getSqlName("select_circleIds"), circleMemberQuery);
	}

	@Override
	public int increaseSignCount(Integer circleId, Integer memberId, int signCount) {
		CircleMember member = new CircleMember();
		member.setCircleId(circleId);
		member.setMemberId(memberId);
		member.setSignCount(signCount);
		return sqlSessionTemplate.update(getSqlName("increaseSignCount"), member);
	}

	@Override
	public int increaseTopicCount(Integer circleId, Integer memberId, int topicCount) {
		CircleMember member = new CircleMember();
		member.setCircleId(circleId);
		member.setMemberId(memberId);
		member.setTopicCount(topicCount);
		return sqlSessionTemplate.update(getSqlName("increaseTopicCount"), member);
	}

	@Override
	public int updateByCircleId(CircleMember member) {
		if(member==null){
			return 0;
		}
		if(member.getCircleId()==null){
			return 0;
		}
		return sqlSessionTemplate.update(getSqlName("updateByCircleId"), member);
	}

	@Override
	public List<Integer> queryMyGroupChatIds(Integer userId) {
		return sqlSessionTemplate.selectList(getSqlName("queryMyGroupChatIds"), userId);
	}

	@Override
	public List<Integer> queryMyCreatedCircleIds(Integer userId) {
		return sqlSessionTemplate.selectList(getSqlName("queryMyCreatedCircleIds"), userId);
	}

	@Override
	public List<Integer> queryCircleMemberIds(Integer circleId) {
		return sqlSessionTemplate.selectList(getSqlName("queryCircleMemberIds"), circleId);
	}

	@Override
	public List<CircleMemberVo> queryCircleFullMember(Integer circleId) {
		return sqlSessionTemplate.selectList(getSqlName("queryCircleFullMember"), circleId);
	}
	@Override
	public List<CircleMemberVo> queryCircleTopicCreators(Integer circleId) {
		return sqlSessionTemplate.selectList(getSqlName("queryCircleTopicCreators"), circleId);
	}

	@Override
	public List<CircleMemberVo> queryPartOfCircleFullMember(Integer circleId) {
		return sqlSessionTemplate.selectList(getSqlName("queryPartOfCircleFullMember"), circleId);
	}
	
}
